<!-- 10.22 嗨我来了个人信息编辑 11.17 修改昵称保存@input -->
<template>
	<app-layout>
		<view>
			<view class="basicf">
				<view class="fbottom">
					<view class="fname">昵称</view>
					<input type="text" class="input" placeholder="请填入昵称" :value="name" @input="blur" />
				</view>
				<view class="fbottom">
					<view class="fname">头像</view>
					<view class="input">
						<view class="logoStore" v-if="islogo == true">
							<view mode="aspectFill" @click='remove' class='remove cross-center main-center'>x</view>
							<image class="image" :src="logoStore" @click='previewImage'></image>
						</view>
						<app-upload-image @cancelon="can" v-else height="170" minheight="170" :islogo="false"
							:value="logoStore" :showNumber="false" @image-event="uploadlogo" maxNum="1" margin="0">
						</app-upload-image>
					</view>
				</view>
				<view class="fbottom">
					<view class="fname">个性签名</view>
					<textarea class="input" placeholder="请填写个性签名" placeholder-class="peditext" name="introduction"
						@input="introcon" style="height:144rpx" :value="introduction" maxlength="-1"></textarea>
				</view>
			</view>
			<view class="befbutton">
				<button class="fbutton bgbut" @click="formSubmit">保存</button>
			</view>
		</view>
		<view :style="{height: BotHeight + 'rpx'}"></view>
	</app-layout>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex';
	import appUploadImage from '../../../components/basic-component/app-upload-image/app-upload-image'
	// 禁止重复提交
	let repid = 0
	let chept = false

	export default {
		name: "apply",
		data() {
			return {
				name: '',
				logoStore: '',
				introduction: '',
				islogo: false
			}
		},
		components: {
			appUploadImage
		},
		computed: {
			...mapState({
				userInfo: state => state.user.info
			}),
			...mapGetters('iPhoneX', {
				BotHeight: 'getBotHeight'
			}),
		},
		onLoad: function(options) {
			repid = 0;
			this.initLoad()
		},
		// onshow 点击预览图片后仍然触发APP页面的onshow
		onShow() {
			if (chept) {
				chept = false
				return
			}
		},
		methods: {
			// 鼠标点击其他地方获取input内内容
			blur(e) {
				this.name = e.target.value
			},
			introcon(e) {
				this.introduction = e.detail.value
			},
			uploadlogo(e) {
				this.logoStore = e.imageList[0]
			},
			remove() {
				this.logoStore = ''
				this.islogo = false
			},
			previewImage() {
				chept = true
				uni.previewImage({
					current: this.logoStore,
					urls: this.logoStore.split(',')
				})
			},
			can(e) {
				console.log(e);
			},
			formSubmit: function(e) {
				const self = this;
				if (!self.name) {
					uni.showToast({
						title: "昵称不能为空",
						icon: 'none'
					});
					return;
				}
				if (self.logoStore == '' || self.logoStore == undefined) {
					uni.showToast({
						title: '头像不能为空',
						icon: "none"
					})
					return
				}
				let adata = {
					nickname: self.name
				}
				if (self.logoStore) {
					adata.avatar = self.logoStore
				}
				if (self.introduction) {
					adata.description = self.introduction
				}
				let aurl = self.$api.sixty.editinfo
				if (repid == 0) {
					repid++;
					self.$request({
						url: aurl,
						data: adata,
						method: 'POST',
					}).then(res => {
						// 11.15 编辑成功后存储到本地 判断是否刷新个人信息
						uni.setStorageSync('haiwolaile', 'hi')
						
						uni.navigateBack({
							delta: 1
						})
					}).catch(e => {
						repid = 0
					})
				}
			},
			initLoad() {
				this.$showLoading();
				this.$request({
					url: this.$api.sixty.mine,
					data: {
						user_id: this.userInfo.options.user_id
					}
				}).then((res) => {
					this.$hideLoading();
					if (res.data.vidianinfo.description) {
						this.introduction = res.data.vidianinfo.description.replaceAll('<p>', '').replaceAll(
							'</p>', '')
					}
					this.name = res.data.userInfo.nickname
					this.logoStore = res.data.userInfo.userInfo.avatar
					this.islogo = true
				}).catch(err => {
					if (err.msg) {
						uni.showToast({
							icon: 'none',
							title: err.msg
						})
					}
					this.$hideLoading();
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	/* 表单 */
	.basicf {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		padding: 42rpx 0;
		width: 686rpx;
		background-color: #FFFFFF;
		margin: 32rpx auto;
		border-radius: 32rpx;
	}

	.fbottom {
		width: 550rpx;
		margin: 0 auto;
		padding: 24rpx 0 0;
		line-height: 72rpx;
		border-bottom: 2rpx solid #F2F2F2;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		color: #333333;
	}

	.fbottom .fname {
		width: 176rpx;
	}

	.peditext {
		color: #999999;
	}

	.fbottom .input {
		width: 374rpx;
	}

	.fbottom .input .logoStore {
		width: 170rpx;
		height: 170rpx;
		position: relative;
	}

	.fbottom .input .logoStore .remove {
		width: 40#{rpx};
		height: 40#{rpx};
		position: absolute;
		right: -16rpx;
		top: -10rpx;
		// background: $uni-important-color-red;
		background: #333333;
		color: #fff;
		border-radius: 50%;
		padding-bottom: 8#{rpx};
		font-size: 24#{rpx};
	}

	.fbottom .input .logoStore .image {
		width: 100%;
		height: 100%;
	}

	.fbottom .input .logoStore.bg {
		background: #F4F4F4;
		position: relative;
	}

	.fbottom .input .logoStore .logoStore-hor {
		position: absolute;
		width: 80rpx;
		height: 2rpx;
		left: 48rpx;
		top: 87rpx;
		background: #FFFFFF;
	}

	.fbottom .input .logoStore .logoStore-ver {
		position: absolute;
		width: 80rpx;
		height: 2rpx;
		left: 48rpx;
		top: 87rpx;
		background: #FFFFFF;
		transform: rotate(90deg);
	}

	.fbottom .input.time {
		display: flex;
		align-items: center;
	}

	.fbottom .input .center {
		padding: 0 20rpx;
	}

	.befbutton {
		background: #342B2A;
		border-radius: 64rpx;
		width: 686rpx;
		height: 88rpx;
		margin: 48rpx auto;
		overflow: hidden;
	}

	.fbutton {
		border-radius: 64rpx;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
		font-weight: bold;
		font-size: 36rpx;
	}

	.bsbut {
		color: #FFFFFF;
		background: #CD9C62;
	}

	.bgbut {
		background: #342B2A;
		color: #FFFFFF;
	}

	.bcbut {
		border: 1rpx solid #342B2A;
		color: #342B2A;
	}
</style>
